#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int Maxn=3005;
int n,m,V;
char s[Maxn][Maxn];


int f[Maxn][Maxn],g[Maxn][Maxn],h[Maxn][Maxn],h1[Maxn][Maxn],res[Maxn][Maxn],res1[Maxn][Maxn];
inline void clear(int lx,int rx,int ly,int ry){
	for(int i=lx-1;i<=rx+1;i++)
		for(int j=ly-1;j<=ry+1;j++)f[i][j]=g[i][j]=res[i][j]=res1[i][j]=0;
}
inline void clear1(int l,int r){
	for(int i=l;i<=r;i++)
		for(int j=l;j<=r;j++)h[i][j]=h1[i][j]=0;
}
int ans;
void solve(int lx,int rx,int ly,int ry){
	if(lx==rx||ly==ry)return;
	clear(lx,rx,ly,ry);
//	if(rx-lx>ry-ly)
	
	
	if(1){
		clear1(ly-1,ry+1);
		int mid=lx+rx>>1;
		solve(lx,mid,ly,ry);solve(mid+1,rx,ly,ry);
		for(int i=ly;i<=ry;i++){
			f[lx][i]=f[rx][i]=1;
			for(int j=lx+1;j<=mid;j++)f[j][i]=1+(s[j][i]==s[j-1][i]?f[j-1][i]:0);
			for(int j=rx-1;j>mid;j--) f[j][i]=1+(s[j][i]==s[j+1][i]?f[j+1][i]:0);
		}
		
		//1
		for(int j=lx;j<=rx;j++)g[j][ry]=ry;
		for(int i=ry-1;i>=ly;i--){
			for(int j=lx;j<=rx;j++){
				if(s[j][i]==s[j][i+1])g[j][i]=g[j][i+1];
				else g[j][i]=i;
			}
		}
		for(int i=ly;i<=ry;i++){
			for(int j=mid+1;j<=mid+f[mid+1][i];j++){
				h[i][g[j][i]]++;
			}
			for(int j=ry-1;j>=ly;j--)h[i][j]+=h[i][j+1];
			for(int j=mid;j>=mid-f[mid][i]+1;j--){
				h1[i][g[j][i]]++;
			}
			for(int j=ry-1;j>=ly;j--)h1[i][j]+=h1[i][j+1];
			
		}
		for(int i=ly;i<=ry;i++){
			for(int j=i+1;j<=ry;j++){
				if(f[mid+1][i]<=f[mid+1][j])res[i][j]=h[i][j];
				if(f[mid][i]<=f[mid][j])res1[i][j]=h1[i][j];
			}
		}
		
		
		clear1(ly,ry);//clear h
		//2
		for(int j=lx;j<=rx;j++)g[j][ly]=ly;
		for(int i=ly+1;i<=ry;i++){
			for(int j=lx;j<=rx;j++){
				if(s[j][i]==s[j][i-1])g[j][i]=g[j][i-1];
				else g[j][i]=i;
			}
		}
		for(int i=ly;i<=ry;i++){
			for(int j=mid+1;j<=mid+f[mid+1][i];j++){
				h[i][g[j][i]]++;
			}
			for(int j=ly+1;j<=ry;j++)h[i][j]+=h[i][j-1];
			
			for(int j=mid;j>=mid-f[mid][i]+1;j--){
				h1[i][g[j][i]]++;
			}
			for(int j=ly+1;j<=ry;j++)h1[i][j]+=h1[i][j-1];
		}
		for(int i=ly;i<=ry;i++){
			for(int j=i+1;j<=ry;j++){
				if(f[mid+1][i]>f[mid+1][j])res[i][j]=h[j][i];
				if(f[mid][i]>f[mid][j])res1[i][j]=h1[j][i];
			}
		}
		
		for(int i=ly;i<=ry;i++)
			for(int j=i+1;j<=ry;j++){
				if(s[mid+1][i]==s[mid][i]&&s[mid+1][i]==s[mid+1][j]&&s[mid][i]==s[mid][j])ans+=res[i][j]*res1[i][j];
				
//				if(s[mid+1][i]==s[mid][i])printf("[%d,%d][%d,%d]:res[%d][%d]=%d,%d  mid=%d\n",lx,rx,ly,ry,i,j,res[i][j],res1[i][j],mid);
				
			}
			
			
			
		clear1(ly,ry);
	}
	
	
}

signed main(){
//	freopen("ex_star1.in","r",stdin);
//	freopen("star.out","w",stdout);
	n=read();m=read();V=max(n,m);
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	solve(1,n,1,m);
	
	printf("%lld\n",ans);
	
	return 0;
}
/*
3 4
aaaa
aaba
aaaa
*/
